package com.tanhua.server.controller;

import com.tanhua.server.service.SettingServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

//    注入servcie对象
    @Autowired
    private SettingServcie settingServcie;

    /**
     * 通用管理设置
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity getSettingData() {
//        调用SettingService方法
        return settingServcie.getSettingData();
    }

    /**
     * 通知管理
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notificationsManager(@RequestBody Map<String,Boolean> map) {
            //分别获取三个参数的值
            Boolean likeNotification = map.get("likeNotification");//喜欢
            Boolean pinglunNotification = map.get("pinglunNotification");//评论
            Boolean gonggaoNotification = map.get("gonggaoNotification");//公告
            //调用service方法 传入三个参数
             return  settingServcie.notificationsManager(
                     likeNotification,pinglunNotification,gonggaoNotification);
    }

    /**
     * 修改手机号- 1 发送短信验证码
     */
    @PostMapping("/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode() {
        //调用servcie方法
        settingServcie.sendVerificationCode();
        //返回
        return ResponseEntity.ok(null);
    }


    /**
     * 设置陌生人消息
     */
    @PostMapping("/questions")
    public ResponseEntity setQuestion(@RequestBody Map map) {
//       获取用户输入的陌生人消息
        String message = (String) map.get("content");
//        调用SettingService方法
        return  settingServcie.setQuestion(message);
    }



    /**
     * 修改手机号 - 2 校验验证码
     */
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map map) {
        String code = (String) map.get("verificationCode");
        //        调用方法校验验证码
        Map resultMap=settingServcie.checkVerificationCode(code);
        //        返回带有map集合的请求体
        return ResponseEntity.ok(resultMap);

    }

    /**
     * 修改手机号 - 3 保存
     */
    @PostMapping("/phone")
    public ResponseEntity editPhone(@RequestBody Map map,@RequestHeader("Authorization") String token) {
//      获取新的手机号码
        String phone = (String) map.get("phone");
//       调用方法 传入phone
        settingServcie.editPhone(phone,token);
        return ResponseEntity.ok(null);


    }



}
